package com.qd.common.sys.domain.entity.person;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.cdqidi.util.page.BaseQuery;
import com.cdqidi.valid.group.DefaultGroup;
import com.cdqidi.valid.group.UpdateGroup;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.Max;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @author sjk
 * 人员
 */
@EqualsAndHashCode(callSuper = true)
@Getter
@Setter
public class PersonDTO extends BaseQuery {
    @JsonIgnore
    @ExcelIgnore
    private static final String EXCEL_TITLE = "人员信息";
    /**
     * 主键
     */
    @ColumnWidth(35)
    @ExcelProperty(value = {EXCEL_TITLE, "人员ID"})
    @NotBlank(message = "人员ID不能为空", groups = UpdateGroup.class)
    @Size(max = 50, message = "人员ID长度不能超过{max}位", groups = DefaultGroup.class)
    private String personId;
    /**
     * 用户账号
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*账号"})
    @NotBlank(message = "账号不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "账号长度不能超过{max}位", groups = DefaultGroup.class)
    private String account;
    /**
     * 用户密码
     */
    @ExcelProperty(value = {EXCEL_TITLE, "密码"})
    @Size(max = 64, message = "密码长度不能超过{max}位", groups = DefaultGroup.class)
    private String password;
//    /**
//     * 头像显示，只用于导出excel
//     */
//    @JsonIgnoreProperties
//    @ExcelProperty(value = {EXCEL_TITLE,"头像"})
//    private File avatarUrl;
    /**
     * 姓名
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*姓名"})
    @NotBlank(message = "姓名不能为空", groups = DefaultGroup.class)
    @Size(max = 200, message = "姓名长度不能超过{max}位", groups = DefaultGroup.class)
    private String personName;
    /**
     * 机构ID
     */
    @ColumnWidth(35)
    @ExcelProperty(value = {EXCEL_TITLE, "*机构ID"})
    @NotBlank(message = "组织机构不能为空", groups = DefaultGroup.class)
    @Size(max = 50, message = "组织机构长度不能超过{max}位", groups = DefaultGroup.class)
    private String orgId;
    /**
     * 机构显示值
     */
    @ColumnWidth(35)
    @ExcelProperty(value = {EXCEL_TITLE, "机构名称"})
    private String orgIdDisplay;
    /**
     * 用户状态:0正常 1停用
     */
    @ExcelIgnore
    @NotNull(message = "用户状态不能为空", groups = DefaultGroup.class)
    @Max(value = 6, message = "用户状态长度不能大于6")
    private Integer userStatus;
    /**
     * 用户状态显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE, "*用户状态"})
    private String userStatusDisplay;
    /**
     * 身份证号
     */
    @ExcelProperty(value = {EXCEL_TITLE, "身份证号"})
    @Size(max = 20, message = "身份证号长度不能超过{max}位", groups = DefaultGroup.class)
    private String idCard;
    /**
     * 手机号
     */
    @ExcelProperty(value = {EXCEL_TITLE, "手机号"})
    @NotBlank(message = "手机号不能为空", groups = DefaultGroup.class)
    @Size(max = 20, message = "手机号长度不能超过{max}位", groups = DefaultGroup.class)
    private String phone;
    /**
     * 用户性别
     */
    @ExcelIgnore
    @Size(max = 50, message = "性别长度不能超过{max}位", groups = DefaultGroup.class)
    private String sex;
    /**
     * 用户性别显示值
     */
    @ExcelProperty(value = {EXCEL_TITLE, "性别"})
    private String sexDisplay;
    /**
     * 用户邮箱
     */
    @ExcelProperty(value = {EXCEL_TITLE, "邮箱"})
    @Size(max = 50, message = "邮箱长度不能超过{max}位", groups = DefaultGroup.class)
    private String email;
    /**
     * 用户头像
     */
    @ExcelIgnore
    @Size(max = 100, message = "头像长度不能超过{max}位", groups = DefaultGroup.class)
    private String avatar;
    /**
     * 用户头像显示值
     */
    @ExcelIgnore
    private String avatarDisplay;
    /**
     * 添加时间
     */
    @ExcelProperty(value = {EXCEL_TITLE, "添加时间"})
    private LocalDateTime addTime;
    /**
     * 修改时间
     */
    @ExcelProperty(value = {EXCEL_TITLE, "修改时间"})
    private LocalDateTime updateTime;
    /**
     * 人员对应的角色信息
     */
    @ExcelIgnore
    private List<PersonRoleDTO> personRoles;


    @Override
    public void freeData() {
        this.personId = null;
        this.account = null;
        this.password = null;
        this.personName = null;
        this.idCard = null;
        this.phone = null;
        this.sex = null;
        this.sexDisplay = null;
        this.email = null;
        this.avatar = null;
        this.avatarDisplay = null;
        this.addTime = null;
        this.updateTime = null;
        this.userStatus = null;
        this.userStatusDisplay = null;
        this.orgId = null;
        this.orgIdDisplay = null;
        if (null != personRoles) {
            personRoles.clear();
            personRoles = null;
        }
        super.freeData();
    }
}
